﻿namespace MyCoreLib.Examples
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using Data;

    public interface IDboUspPersonDetailsEnumerator : IDataRecordEnumerator,
        IEnumerator<IDboUspPersonDetailsResult>,
        IEnumerator<IDboUspPersonDetailsResult2>,
        IEnumerator<IDboUspPersonDetailsResult3>
    {
    }

    public abstract class DboUspPersonDetailsReader
    {
        protected abstract void Read(IEnumerator<IDboUspPersonDetailsResult> resultSet);
        protected abstract void Read(IEnumerator<IDboUspPersonDetailsResult2> resultSet);
        protected abstract void Read(IEnumerator<IDboUspPersonDetailsResult3> resultSet);

        public void Read(IDboUspPersonDetailsEnumerator enumerator)
        {
            this.Read((IEnumerator<IDboUspPersonDetailsResult>)enumerator);
            this.Read((IEnumerator<IDboUspPersonDetailsResult2>)enumerator);
            this.Read((IEnumerator<IDboUspPersonDetailsResult3>)enumerator);
        }
    }


    public class DboUspPersonDetailsEnumerator : DataRecordEnumerator<SqlDataReader>, IDboUspPersonDetailsEnumerator
    {        
        public DboUspPersonDetailsEnumerator(SqlDataReader reader) 
            : base(reader: reader, resultSetsCount: 3)
        {
        }



        IDboUspPersonDetailsResult IEnumerator<IDboUspPersonDetailsResult>.Current
        {
            get
            {
                ThrowIfDisposed();
                if (CurrentResultSetIndex != 0)
                {
                    throw new InvalidOperationException();
                }
                return new DboUspPersonDetailsResult(this.CurrentDataRecord);
            }
        }

        IDboUspPersonDetailsResult2 IEnumerator<IDboUspPersonDetailsResult2>.Current
        {
            get
            {
                ThrowIfDisposed();
                if (CurrentResultSetIndex != 1)
                {
                    throw new InvalidOperationException();
                }
                throw new NotImplementedException();
            }
        }

        IDboUspPersonDetailsResult3 IEnumerator<IDboUspPersonDetailsResult3>.Current
        {
            get
            {
                ThrowIfDisposed();
                if (CurrentResultSetIndex != 2)
                {
                    throw new InvalidOperationException();
                }
                throw new NotImplementedException();
            }
        }
    }

    public interface IDboUspPersonDetailsResult : IPerson
    {
    }

    public interface IDboUspPersonDetailsResult2
    {
    }


    public interface IDboUspPersonDetailsResult3
    {
    }

    public class DboUspPersonDetailsResult : IDboUspPersonDetailsResult
    {        

        internal DboUspPersonDetailsResult(System.Data.IDataRecord record)
        {
            this.Id = record[0] is DBNull ? Guid.Empty : record.GetGuid(0);
            this.FirstName = record[1] is DBNull ? null : record.GetString(1);
            this.LastName = record[2] is DBNull ? null : record.GetString(2);
        }

        public Guid Id { get; private set; }

        public string FirstName { get; private set; }

        public string LastName { get; private set; }


        Guid IPerson.Id
        {
            get { return this.Id; }
        }

        string IPerson.FirstName
        {
            get { return this.FirstName; }
        }

        string IPerson.LastName
        {
            get { return this.LastName; }
        }
    }

    public class DboUspPersonDetailsResult2 : IDboUspPersonDetailsResult2
    {

    }

    public class DboUspPersonDetailsResult3 : IDboUspPersonDetailsResult3
    {

    }

}
